<?php

/*
 * Set up the content width value based on the theme's design.
 *
 * @see twentythirteen_content_width() for template-specific adjustments.
 */
if ( ! isset( $content_width ) )
	$content_width = 1024;

global $PAGE_ABOUT_ID;
global $PAGE_CENTER_ID;
$PAGE_ABOUT_ID = 2;
$PAGE_CENTER_ID = 37;

function usc_theme_setup() {
	add_theme_support( 'post-thumbnails' );

	register_nav_menu( 'primary', __( 'Navigation Menu', 'us-china' ) );
	add_filter('show_admin_bar', '__return_false');
}
add_action( 'after_setup_theme', 'usc_theme_setup' );

/**
 * Register widget areas.
 *
 * @since US-China 1.0
 */
function usc_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Main Widget Area', 'us-china' ),
		'id'            => 'sidebar-menu',
		'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'usc_widgets_init' );

/**
 * Enqueue scripts and styles for the front end.
 *
 * @since US-China 1.0
 */
function usc_scripts_styles() {
	/*
	 * Adds JavaScript to pages with the comment form to support
	 * sites with threaded comments (when in use).
	 */

	// Loads our main stylesheet.
	wp_enqueue_style( 'usc-main-style', get_stylesheet_uri(), array(), '2014-11-18' );

}
add_action( 'wp_enqueue_scripts', 'usc_scripts_styles' );

if ( ! function_exists( 'twentythirteen_paging_nav' ) ) :
/**
 * Display navigation to next/previous set of posts when applicable.
 *
 * @since Twenty Thirteen 1.0
 */
function twentythirteen_paging_nav() {
	global $wp_query;

	// Don't print empty markup if there's only one page.
	if ( $wp_query->max_num_pages < 2 )
		return;
	?>
	<nav class="navigation paging-navigation" role="navigation">
		<h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1>
		<div class="nav-links">

			<?php if ( get_next_posts_link() ) : ?>
			<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentythirteen' ) ); ?></div>
			<?php endif; ?>

			<?php if ( get_previous_posts_link() ) : ?>
			<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentythirteen' ) ); ?></div>
			<?php endif; ?>

		</div><!-- .nav-links -->
	</nav><!-- .navigation -->
	<?php
}
endif;

if ( ! function_exists( 'twentythirteen_entry_date' ) ) :
/**
 * Print HTML with date information for current post.
 *
 * Create your own twentythirteen_entry_date() to override in a child theme.
 *
 * @since Twenty Thirteen 1.0
 *
 * @param boolean $echo (optional) Whether to echo the date. Default true.
 * @return string The HTML-formatted post date.
 */
function twentythirteen_entry_date( $echo = true ) {
	if ( has_post_format( array( 'chat', 'status' ) ) )
		$format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' );
	else
		$format_prefix = '%2$s';

	$date = sprintf( '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>',
		esc_url( get_permalink() ),
		esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ),
		esc_attr( get_the_date( 'c' ) ),
		esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
	);

	if ( $echo )
		echo $date;

	return $date;
}
endif;

if ( ! function_exists( 'twentythirteen_entry_meta' ) ) :
/**
 * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
 *
 * Create your own twentythirteen_entry_meta() to override in a child theme.
 *
 * @since Twenty Thirteen 1.0
 */
function twentythirteen_entry_meta() {
	if ( is_sticky() && is_home() && ! is_paged() )
		echo '<span class="featured-post">' . __( 'Sticky', 'twentythirteen' ) . '</span>';

	if ( ! has_post_format( 'link' ) && 'post' == get_post_type() )
		twentythirteen_entry_date();

	// Translators: used between list items, there is a space after the comma.
	$categories_list = get_the_category_list( __( ', ', 'twentythirteen' ) );
	if ( $categories_list ) {
		echo '<span class="categories-links">' . $categories_list . '</span>';
	}

	// Translators: used between list items, there is a space after the comma.
	$tag_list = get_the_tag_list( '', __( ', ', 'twentythirteen' ) );
	if ( $tag_list ) {
		echo '<span class="tags-links">' . $tag_list . '</span>';
	}

	// Post author
	if ( 'post' == get_post_type() ) {
		printf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ),
			get_the_author()
		);
	}
}
endif;


if ( ! function_exists( 'the_category_table' ) ) :

function the_category_table($slug, $num = 1 ) {
	$class_name = "category_$slug";
	$cat = get_category_by_slug($slug);
	?>
	<table class="category_table <?php echo $class_name; ?>_table">
		<tr>
			<td Colspan=4 class="category_table_name <?php echo $class_name; ?>_table_name"><?php echo $cat->category_description; ?></td>
		</tr>
		<tr>
			<td class="category_table_head <?php echo $class_name; ?>_table_head">FOA</td>
			<td class="category_table_head <?php echo $class_name; ?>_table_head">Title</td>
			<td class="category_table_head <?php echo $class_name; ?>_table_head">Application Receipt Date(s)</td>
			<td class="category_table_head <?php echo $class_name; ?>_table_head">Expires</td>
		</tr>
		<?php query_posts("cat=$cat->term_id&showposts=$num"); ?>
		<?php while (have_posts()) : the_post(); ?>
			<?php get_template_part( 'table', $slug ); ?>
		<?php endwhile; ?>
	</table>
	<?php
}
endif;

if ( ! function_exists( 'the_category_section' ) ) :
/**
 * Print HTML with meta information for current post: categories, tags, permalink, author, and date.
 *
 * Create your own the_section() to override in a child theme.
 *
 * @since US-China
 */
function the_category_section($slug, $num = -1 ) {
	$cat = get_category_by_slug($slug);
	if ( $cat ) :
	?>
	<div class="section section-<?php echo $slug; ?>">
		<div class="section-title-<?php echo $slug; ?>"><?php echo $cat->name; ?></div>
		<div class="section-container section-container-<?php echo $slug; ?>">
			<?php
			query_posts("cat=$cat->term_id&showposts=$num");
			while (have_posts()) : the_post();
				$template_file = locate_template('section-' . $slug . '.php');
				include( $template_file != '' ? $template_file : 'section.php');
			endwhile;
			?>
		</div>
	</div>
	<?php
	endif;
}
endif;

if ( ! function_exists( 'usa_the_shortcode_content' ) ) :
function usa_the_shortcode_content($shortcode) {
	$content = apply_filters('the_content', $shortcode);
	$content = str_replace(']]>', ']]&gt;', $content);
	echo $content;
}
endif;

?>
